import unittest

import stackless

import world,display

import utils,items

import charectors

class _Display(display.Display):
    def update(self,rects):
        pass

#TODO : there is some repeation in tests like loadMap a lot ...
#       We should have some refactoring

class TestLoadMap(unittest.TestCase):
    
    def setUp(self):
        self.display=_Display()
        self.world=world.World(self.display)

    def testOneWall(self):
        '''test a single unit filled with a wall''' 

        self.assertEqual(len(utils.loadMap(self.world,['#'])),1)

    def testTypeOfWall(self):
        '''Trying different type of wall'''

        x=utils.loadMap(self.world,['#'])[0]
        assert isinstance(x,items.UnDestroyableWall)

        x=utils.loadMap(self.world,['X'])[0]
        assert isinstance(x,items.DestroyableWall)

    def testWallPos(self):
        '''Testing if the wall is at the right position'''

        x=utils.loadMap(self.world,['#'])[0]
        self.assertEqual(x.pos,(self.display.unitsize[0]/2,self.display.unitsize[1]/2))

    def testEmpty(self):
        '''Testing some place that is empty'''

        x=utils.loadMap(self.world,['.'])
        self.assertEqual(len(x),0)

    def testBornPlace(self):
        '''Testing some place of our charector's start posistion'''
        x=utils.loadMap(self.world,['*'])[0]

        assert isinstance(x,charectors.BasicCharector)

    def testGold(self):
        '''Testing some Gold'''


        x=utils.loadMap(self.world,['$'])[0]

        assert isinstance(x,items.Gold)
        self.assertEqual(x.value,10)


unittest.main()
